/* 
  管理网络请求接口，所有网络请求都已通过方法封装好
*/
import request from "./request";
import qs from "qs";

interface AdminLoginData {
  username: string;
  password: string;
}

// 对Promise类型别名的封装
type PromiseRes<T = {}> = Promise<ManageResult<T>>;

// 该项目请求回来的顶级对象类型接口
interface ManageResult<T> {
  code: number;
  data: T;
  message: string;
  errmsg?: string;
  errno?: number;
}

/*
 * 以下是响应参数的接口类型
 *
 */

// 用户登录token接口类型
interface AdminLoginRes {
  token: string;
  tokenHead: string;
}

// 用户信息接口类型
interface AdminLoginInfo {
  menus: [];
  icon: "";
  roles: [];
  username: "";
}

// 用户列表接口类型
interface UserListItf {
  pageNum: number;
  pageSize: number;
  totalPage: number;
  total: number;
  list: {
    id: number;
    username: string;
    icon: string;
    email: string;
    nickName: string;
    note: string;
    createTime: string;
    loginTime: string;
    password: string;
    status: number;
  }[];
}

// 用户角色类型别名
type UserRolesItf = [
  {
    adminCount: number;
    createTime: string;
    description: string;
    id: number;
    name: string;
    sort: number;
    status: number;
  }
];

// 品牌推荐列表接口类型
interface brandListItf {
  list: [
    {
      brandId: number;
      brandName: string;
      id: number;
      recommendStatus: number;
      sort: number;
    }
  ];
  pageNum: number;
  pageSize: number;
  total: number;
  totalPage: number;
}

<<<<<<< HEAD
// data类型
interface UserInfo {
  [x: string]: any[];
=======
// 商品列表数据接口类型
interface productListItf<T> {
  pageNum: number;
  pageSize: number;
  totalPage: number;
  total: number;
  list: T; // 全局类型别名 productInfoType
>>>>>>> 03b452233e741cde7481a14afa72ad54c623fb33
}

/*
 * 用户token、左侧列表渲染、用户列表页面
 *
 */
// 获取首页echarts信息
export const getIndexEchartsApi = (): PromiseRes<indexEchartsItf> =>
  request.get("http://kumanxuan1.f3322.net:8360/admin/stat");

// 获取用户token
export const getUserTokenApi = (
  data: AdminLoginData
): PromiseRes<AdminLoginRes> => request.post("/admin/login", data);

// 通过用户token拿到用户信息
export const getUserInfiApi = (): PromiseRes<AdminLoginInfo> =>
  request.get("/admin/info");

// 获取用户列表
export const getUserListApi = (params: {}): PromiseRes<UserListItf> =>
  request.get("/admin/list", { params });

// 修改用户信息
export const updateUserInfoApi = (id: number, data: {}): PromiseRes =>
  request.post("/admin/update/" + id, data);

// 修改用户status状态
export const updateUserStatus = (
  id: number,
  status: number
): PromiseRes<string> =>
  request.post("/admin/updateStatus/" + id + "?status=" + status);

// 获取用户分配角色信息
export const getUserRolesApi = (id: number): PromiseRes<UserRolesItf> =>
  request.get("/admin/role/" + id);

// 修改用户分配角色
export const updateUserRoles = (data: {
  adminId: string;
  roleIds: string;
}): PromiseRes<number> =>
  request.post("/admin/role/update", qs.stringify(data));

// 添加用户
export const addUserApi = (data: {}): PromiseRes<userInfoItf> =>
  request.post("/admin/register", data);

// 筛选搜索
export const searchUserApi = (
  keyword: string,
  pageNum: number = 1,
  pageSize: number = 10
): PromiseRes<UserListItf> =>
  request.get(
    `/admin/list?keyword=${keyword}&pageNum=${pageNum}&pageSize=${pageSize}`
  );

/*
 * 品牌推荐
 *
 */
// 获取品牌推荐数据
export const getBrandListApi = (
  pageNum: number,
  pageSize: number
): PromiseRes<brandListItf> =>
  request.get("/home/brand/list?pageNum=" + pageNum + "&pageSize=" + pageSize);

// 批量操作品牌推荐数据(设置推荐&不推荐)
export const changeRecommendStatusApi = (data: {}): PromiseRes =>
  request.post("/home/brand/update/recommendStatus", qs.stringify(data));

// 批量删除品牌推荐数据
export const deleteRecommendApi = (data: {}): PromiseRes =>
  request.post("/home/brand/delete", qs.stringify(data));

/*
<<<<<<< HEAD
 * 营销 限时活动管理
 *
 */
//根据活动名称分页查询
export const FlashListApi = (data: {}): PromiseRes<brandListItf> =>
  request.get("/flash/list", { params: data });

//修改活动上下线状态
export const changeFlashStatusApi = (
  id: number,
  data: {
    status: number;
  }
): PromiseRes =>
  request.post("/flash/update/status/" + id, null, { params: data });

//获取全部可选场次及其数量
export const selectListApi = (data: {}): PromiseRes<{}[]> =>
  request.get("/flashSession/selectList", { params: data });

//分页查询不同场次关联及商品信息

export const flashProductRelationListApi = (data: {}): PromiseRes<{}[]> =>
  request.get("/flashProductRelation/list", { params: data });
=======
 * 商品菜单Api
 *
 */
// 获取商品列表
export const getProductListApi = (params: {}): PromiseRes<
  productListItf<productInfoType>
> => request.get("/product/list", { params });
>>>>>>> 03b452233e741cde7481a14afa72ad54c623fb33
